//
// Copyright (c) 2024 BPer
//

#ifndef INCLUDE_BPERUTIL_BPERAVCTYPE_H_
#define INCLUDE_BPERUTIL_BPERAVCTYPE_H_

#include <bperutil/BPerType.h>
#define BPER_FrameType_Spspps 9
#define BPER_FrameType_I 1
#define BPER_FrameType_P 0

#define BPer_MJPEG_Header 0x37

typedef enum  {
	BPerRecvonly, BPerSendonly, BPerSendrecv
}BPerRtcDirection;

typedef enum {
    BPer_Conn_State_New,
    BPer_Conn_State_Connecting,
    BPer_Conn_State_Connected,
    BPer_Conn_State_Disconnected,
    BPer_Conn_State_Failed,
    BPer_Conn_State_Closed
}BPerRtcConnectionState;

typedef enum BPerAudioCodec{
	BPer_AED_AAC,
	BPer_AED_MP3,
	BPer_AED_SPEEX,
	BPer_AED_OPUS,
	BPer_AED_PCMA,
	BPer_AED_PCMU
}BPerAudioCodec;

typedef enum BPerVideoCodec{
	BPer_VED_H264,
	BPer_VED_H265,
	BPer_VED_AV1,
	BPer_VED_VP8,
	BPer_VED_VP9,
	BPer_VED_MJPEG
}BPerVideoCodec;

typedef enum BPerRequestType {
	BPer_Req_Sendkeyframe,
	BPer_Req_HighLostPacketRate,
	BPer_Req_LowLostPacketRate,
	BPer_Req_Connected,
	BPer_Req_Disconnected
}BPerRequestType;

typedef enum BPerRtcMessageType{
	BPerRTC_Decoder_Error
}BPerRtcMessageType;

typedef enum{
	BPerIceHost,
	BPerIceStun,
	BPerIceTurn
}BPerIceCandidateType;

typedef enum {
	BPerIceNew,
    BPerIceSuccess,
    BPerIceFail
}BPerIceCandidateState;

typedef struct{
	int32_t mediaType;
	int32_t uid;
	int32_t frametype;
	int32_t nb;
	int64_t pts;
	int64_t dts;
	uint8_t* payload;
}BPerFrame;

typedef struct {
	enum BPerAudioCodec encode;
	int32_t sample;
	int32_t channel;
    int32_t audioClock;
    int32_t fec;
}BPerAudioParam;

typedef struct  {
	enum BPerVideoCodec encode;
	int32_t videoClock;
}BPerVideoParam;

typedef struct{
 void* context;
 int32_t (*sendRtcMessage)(void* context,int puid,BPerRtcMessageType mess);
}BPerSendRtcMessage;



typedef struct{
	BPerIpFamilyType familyType;
	int32_t serverPort;
	uint32_t stunIp;
	int32_t stunPort;
	uint32_t relayIp;
	int32_t relayPort;
	char username[64];
	char password[64];
	char serverIp[64];
}BPerIceServer;

typedef struct{
	void* context;
	void (*sslAlert)(void* context,int32_t uid,char* type,char* desc);
}BPerSslCallback;

typedef struct {
	 void* context;
	 void (*receiveAudio)(void* context,BPerFrame *audioFrame);
	 void (*receiveVideo)(void* context,BPerFrame *videoFrame);
	 void (*receiveMsg)(void* context,BPerFrame *videoFrame);
}BPerReceiveCallback;

typedef struct{
	void* context;
	void (*onIceStateChange)(void* context,int32_t uid,BPerIceCandidateType iceCandidateType,BPerIceCandidateState iceState);
	void (*onConnectionStateChange)(void* context, int32_t uid,BPerRtcConnectionState connectionState);
}BPerIceCallback;

typedef struct{
	void* context;
	void (*setMediaConfig)(void* context,int32_t puid,BPerAudioParam* audio,BPerVideoParam* video);
	void (*sendRequest)(void* context,int32_t puid,uint32_t ssrc,BPerRequestType req);
}BPerRtcCallback;

typedef struct  {

	int32_t localPort;
	int32_t remotePort;
	int32_t uid;
	BPerBool isControlled;

	BPerRtcDirection direction;
	BPerSslCallback sslCallback;
	BPerRtcCallback rtcCallback;
	BPerReceiveCallback recvCallback;
	BPerIceCallback iceCallback;

	char url[160];
	char remoteIp[64];
	char app[32];
	char stream[BPer_StreamName_Lenght];
}BPerStreamConfig;

#endif /* INCLUDE_BPERUTIL_BPERAVCTYPE_H_ */
